package cn.glutnn.subject.domain.handler.subject;

import cn.glutnn.subject.common.enums.SubjectInfoTypeEnum;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Author:   msh
 * Date:     2024/11/28 下午3:16
 * Description: 题目类型处理器工厂
 */

@Component
public class SubjectTypeHandlerFactory {
    @Resource
    private List<SubjectTypeHandler> subjectTypeHandlers;

    // 根据题目类型获取对应的处理器, 找不到就抛出异常
    public SubjectTypeHandler getHandler(int subjectType) {
        return subjectTypeHandlers.stream()
                .filter(handler -> handler.getHandlerType().getCode() == subjectType)
                .findFirst()
                .orElseThrow(() -> new RuntimeException("题目类型不存在"));
    }
}
